<?php

namespace business\elasticsearch\repositories;


use business\elasticsearch\models\NewsModel;
use yii\elasticsearch\Query;

class NewsRepository
{

    public function queryList(
        $condition = [],
        $include = [],
        $from = 0,
        $size = 0,
        $highlight = [],
        $orderBy = []
    ) {
        $query = (new Query())
            ->source($include)
            ->from(NewsModel::index(), NewsModel::type())
            ->query($condition);

        !empty($highlight) && $query->highlight($highlight);
        !empty($orderBy) && $query->orderBy($orderBy);

        $query->offset($from)->limit($size);

        return [
            $query->count(),
            $query->all()
        ];
    }
}